package cn.zn.modules.budget.cur.controller;

import cn.hutool.http.HttpStatus;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.budget.cur.entity.TBudgetIncomeTag;
import cn.zn.modules.budget.cur.service.TBudgetIncomeTagService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 收入标记
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2019-12-10 14:27:52
 */
@RestController
@RequestMapping("budget/budgetincometag")
public class TBudgetIncomeTagController {

    @Autowired
    private TBudgetIncomeTagService tBudgetIncomeTagService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("budget:tbudgetincometag:list")
    public R list(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("incomeId")) {
            return R.error(HttpStatus.HTTP_BAD_REQUEST, "incomeId 不能为空");
        }
        PageUtils pageUtils = tBudgetIncomeTagService.queryPage(params);

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("budget:tbudgetincometag:info")
    public R info(@PathVariable("id") String id) {
        TBudgetIncomeTag tBudgetIncomeTag = tBudgetIncomeTagService.getById(id);

        return R.ok().put("tBudgetIncomeTag", tBudgetIncomeTag);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("budget:tbudgetincometag:save")
    public R save(@RequestBody TBudgetIncomeTag tBudgetIncomeTag) {
        tBudgetIncomeTagService.save(tBudgetIncomeTag);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("budget:tbudgetincometag:update")
    public R update(@RequestBody TBudgetIncomeTag tBudgetIncomeTag) {
        tBudgetIncomeTagService.updateById(tBudgetIncomeTag);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("budget:tbudgetincometag:delete")
    public R delete(@RequestBody String[] ids) {
        tBudgetIncomeTagService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
